package com.zlzxm.shoesmarket.view.activity;

import android.app.Activity;
import android.content.Intent;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.google.android.flexbox.FlexboxLayoutManager;
import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.util.ZViewHelp;
import com.zlzxm.shoesmarket.view.activity.manage.StartBundleKey;
import com.zlzxm.shoesmarket.view.activity.manage.bundle.BundleGoodsInfo;
import com.zlzxm.shoesmarket.view.adapter.ADGoodsSizeTag;
import com.zlzxm.shoesmarket.view.widget.GoodsInfoView;
import com.zlzxm.shoesmarket.view.widget.simpleead.SimpleHead;
import com.zlzxm.shoesmarket.viewmodel.VMTransferGoods;

/**
 * CREATE BY zlzxm ON 4/16/21
 * <br> 调货
 */
public class ACTransferGoods extends BaseActivity implements OnItemClickListener {


    public static void start(Activity  activity , BundleGoodsInfo bundleGoodsInfo) {
        Intent starter = new Intent(activity, ACTransferGoods.class);

        starter.putExtra(StartBundleKey.KEY_GOODS_INFO, bundleGoodsInfo);
        activity.startActivity(starter);

    }


    private VMTransferGoods vmTransferGoods;

    private GoodsInfoView goodsInfoView;

    private RecyclerView rvSize;

    private ADGoodsSizeTag adGoodsSizeTag = new ADGoodsSizeTag();

    @Override
    protected void initView() {
        super.initView();
        setContentView(R.layout.ac_transfer_goods);
        SimpleHead simpleHead = ZViewHelp.findById(this,R.id.head);
        simpleHead.setTitle("调货");
        simpleHead.setOnItemclicklistener(this::finish);
        goodsInfoView  = ZViewHelp.findById(this,R.id.goodsInfoView);

        rvSize = ZViewHelp.findById(this,R.id.rvSize);

        rvSize.setLayoutManager(new FlexboxLayoutManager(this));

        adGoodsSizeTag.setOnItemClickListener(this);
    }

    @Override
    protected void initViewModule() {
        super.initViewModule();
        vmTransferGoods = new ViewModelProvider(this).get(VMTransferGoods.class);

        vmTransferGoods.getLiveGoodsInfo().observe(this,it ->{
////
////            updateGoodsInfo(it.getBrand(),it.getCode(),
////                    it.getName(),it.getFace());
//
//            adGoodsSizeTag.setList(it.getList());


        });
    }

    @Override
    protected void initData() {
        super.initData();
        BundleGoodsInfo bundleGoodsInfo = (BundleGoodsInfo) getIntent().getSerializableExtra(StartBundleKey.KEY_GOODS_INFO);

        updateGoodsInfo(bundleGoodsInfo.getBrand(), bundleGoodsInfo.getCode(),
                bundleGoodsInfo.getName(), bundleGoodsInfo.getFace());
        rvSize.setAdapter(adGoodsSizeTag);
        vmTransferGoods.requestInfo();
    }

    @Override
    public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {

        adGoodsSizeTag.setSelectPosition(position);
    }

    private void updateGoodsInfo(String brand,String code,String name,String face){

        goodsInfoView.updateBrand(brand);
        goodsInfoView.updateCode(code);
        goodsInfoView.updateName(name);
        goodsInfoView.updateFace(face);


    }


}
